/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author Mirza
 */
public class Suplier extends DatabaseModel {
    // nama-nama field dalam tabel
    private String kodeSuplier;
    private String namaSuplier;
    private String alamat;
    private String contactPerson;

    public Suplier() {
        super();
    }

    @Override
    public boolean insertTransaction() {
        try {
            String sql = "insert into suplier(`nama_suplier`,`alamat`,`contact_person`) values('" +namaSuplier+ "','" + alamat + "','" + contactPerson + "')";
            super.statement.execute(sql);
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(Barang.class.getName()).log(Level.SEVERE, null, ex);
        }
        return false;
    }

    @Override
    public boolean updateTransaction() {
        try {
            String sql = "update suplier set nama_suplier = '"+namaSuplier+"', alamat = '"+alamat+"',contact_person = '"+contactPerson+"' where kode_suplier = '"+kodeSuplier+"'";
            super.statement.execute(sql);
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(Barang.class.getName()).log(Level.SEVERE, null, ex);
        }
        return false;
    }

    @Override
    public boolean deleteTransaction() {
        try {
            String sql = "delete from suplier where kode_suplier = '"+kodeSuplier+"'";
            super.statement.execute(sql);
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(Barang.class.getName()).log(Level.SEVERE, null, ex);
        }
        return false;
    }

    @Override
    public ResultSet getData(String filter) {
        try {
            String sql = "select * from suplier " + filter;
            return super.statement.executeQuery(sql);
        } catch (SQLException ex) {
            Logger.getLogger(Suplier.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    /**
     * @param kodeSuplier the kodeSuplier to set
     */
    public void setKodeSuplier(String kodeSuplier) {
        this.kodeSuplier = kodeSuplier;
    }

    /**
     * @param namaSuplier the namaSuplier to set
     */
    public void setNamaSuplier(String namaSuplier) {
        this.namaSuplier = namaSuplier;
    }

    /**
     * @param alamat the alamat to set
     */
    public void setAlamat(String alamat) {
        this.alamat = alamat;
    }

    /**
     * @param contactPerson the contactPerson to set
     */
    public void setContactPerson(String contactPerson) {
        this.contactPerson = contactPerson;
    }
}
